<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="体温" prop="temperature">
        <el-input v-model="form.temperature"></el-input>
      </el-form-item>

      <el-form-item label="是否健康" prop="healthy">
        <el-radio-group v-model="form.healthy">
          <el-radio label="健康"></el-radio>
          <el-radio label="状态不佳"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="是否外出" prop="goOut">
        <el-radio-group v-model="form.goOut">
          <el-radio label="是"></el-radio>
          <el-radio label="否"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="工作状态" prop="work">
        <el-radio-group v-model="form.work">
          <el-radio label="留校办公"></el-radio>
          <el-radio label="出差"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" v-model="form.remark"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit('form')">打卡</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {toDate} from "element-ui/src/utils/date-util";

export default {
  data() {
    return {
      sid: '',
      state: '',
      form: {
        temperature: '',
        goOut: '',
        work: '',
        healthy: '',
        remark: '',
        clockId: '',
        userId: ''
      },
      rules: {
        temperature: [
          { required: true, message: '请输入当日体温', trigger: 'blur' },
          { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        ],
        goOut: [
          { required: true, message: '请选择是否外出', trigger: 'blur' }
        ],
        work: [
          { required: true, message: '请选择工作状态', trigger: 'blur' }
        ],
        healthy: [
          { required: true, message: '请选择是否健康', trigger: 'blur' }
        ],
        remark: [
          { min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
        ],
      }
    }
  },
  created() {
    console.log(this.Global.clockId);
    let _this = this;
    axios.get('http://localhost:1234/clockedState/'+ this.Global.clockId +'').then(function (resp){
      console.log(resp);
      if(resp.data==1){
        axios.get('http://localhost:1234/selectClocked/'+ _this.Global.clockId +'').then(function (resp){
          console.log(resp);
          _this.form = resp.data;
        })
      }else{
      }
    })
  },
  methods: {
    onSubmit(formName) {
      console.log("0",this.form);
      const _this = this;
      this.$refs[formName].validate((valid) => {
        // 如果全部校验好了，valid为true
        if (valid) {
          axios.get('http://localhost:1234/clockedState/'+ this.Global.clockId +'').then(function (resp){
            _this.form.clockId = _this.Global.clockId;
            _this.form.userId = _this.Global.userId;
            axios.post('http://localhost:1234/updateClocked',_this.form).then(function (resp){
              if(resp.data==1){
                _this.$router.back();
              }
            })
          })
          if(_this.state==1){

          }else{

          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  }
}
</script>

<style scoped>

</style>
